<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基数排序</title>
</head>
<body>
    <script>
        // 基数排序：将一个数的个位十位百位等依次排序，然后再进行合并，分桶：0-9，每个数的个位十位也是0-9，按着此规律把数进行分桶，直到把最大的数排完就结束分组
        function redixSort(arr) {
            let base = 10
            let divider = 1

            while(divider <= Math.max(...arr)) {
                let bockts = [...Array(10)].map(()=> [])
                for(let item of arr) {
                    bockts[Math.floor(item/divider)%base].push(item)
                }
                arr = [].concat(...bockts)
                divider*= base
                console.log(divider)
            }
            return arr
        }
        console.log(redixSort([2345,5643,6784,5678,3453]))
    </script>
</body>
</html>